
const slide = async(page)=>{
    return new Promise(async (resolve,reject)=>{
        let nocaptcha = await page.evaluate(()=>{
           return document.querySelector('#nocaptcha').getBoundingClientRect().x>0;
        });
        console.log('nocaptcha',nocaptcha)
        if(nocaptcha){
            console.log('need slide');
            let _block = await await page.$('#nc_1_n1z')
            await page.evaluate(()=>{
                let box = document.querySelector('.login-box-warp');
                box.setAttribute('style','letf:1px;right:auto');
            });
            await page.waitFor(3000);
            let track = await page.evaluate(()=>{
                let step = 20;
                let slider = document.querySelector('#nc_1__scale_text');
                let block = document.querySelector('#nc_1_n1z');
                let sBound = slider.getBoundingClientRect();
                let bBound = block.getBoundingClientRect();
                let track = [];
                let xStart = parseFloat(sBound.x*1.0+bBound.width*0.5);
                let xEnd = parseFloat(sBound.x*1.0+sBound.width*1.0);
                let y = parseFloat(sBound.y*1.0+bBound.height*0.5);
                let distance = (sBound.width*1.0)/(step-1); 
                track.push([xStart,y+1]);
                for(let i = 0;i<step-2;i++){
                    track.push([xStart+i*distance,y]);
                }
                track.push([xEnd,y-2]);
                return track;
            }); 

            // let slider = await page.$('#nc_1__scale_text');
            // let sBound = {};
            // await slider.boundingBox().then(r=>{sBound = r});
            // console.log('sBound',sBound);
            // let block = await page.$('#nc_1_n1z');
            // let bBound = {};
            // await block.boundingBox().then(r=>{bBound = r});
            // console.log('bBound',bBound);
            // let track = [
            //     [parseInt(sBound.x + bBound.width*0.5),parseInt(sBound.y+bBound.height*0.5)],
            //     [parseInt(sBound.x + sBound.width - bBound.width*0.5),parseInt(sBound.y+bBound.height*0.5)]
            // ];
           
            //await _block.click();
            await page.waitFor(3000);
            console.log(track);
            for(let i =0;i<track.length;i++){
                await page.mouse.move(...track[i]);
                await page.waitFor(30);
                if(i==0){
                    await page.mouse.down();
                }
                else if(i==track.length){
                    await page.mouse.up();
                }
            }
            await page.waitFor(300000);
           let errloading = await page.evaluate(()=>{
                return document.querySelector('#nocaptcha .errloading')!=null;
            });
            resolve('clear');
        }
        else{
            resolve('clear');
        }
        
    });
};
module.exports = slide;